﻿<Local:NavigationView
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="SeriesManager.View.AirView"
    NavigationCacheMode="Enabled"
    
    xmlns:Converter="using:SeriesManager.Converter"
    xmlns:Local="using:SeriesManager.View">
    
    <Page.Resources>
        <Converter:DateStringConverter x:Key="DateStringConverter" />
        <Converter:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter" />
        <Converter:AirViewConverter x:Key="AirViewConverter" />
        <DataTemplate x:Key="itemTemplate">
            <Grid Width="186" Height="300">
                <Image Source="{Binding Season.Banner.LocalPath}" Stretch="UniformToFill" Margin="0,24,0,0" />

                <Grid Background="#4372AA" VerticalAlignment="Top">
                    <TextBlock Padding="4,2" VerticalAlignment="Center" TextAlignment="Center" FontSize="18" Foreground="White" Text="{Binding FirstAired, Converter={StaticResource DateStringConverter}}" Opacity="0.8" />
                </Grid>

                <Border Padding="4,2" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Background="#4372AA">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock FontSize="18" Foreground="White" Text="{Binding Number}" />
                        <TextBlock FontSize="18" Foreground="White" Text="&#160;-&#160;" Grid.Column="1" />
                        <TextBlock FontSize="18" Foreground="White" Text="{Binding Name}" TextTrimming="CharacterEllipsis" Grid.Column="2" />
                    </Grid>
                </Border>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition />
        </Grid.RowDefinitions>
        
        <GridView
            x:Name="gridView"
            Padding="116,140,40,50"
            Grid.RowSpan="2"
            Style="{StaticResource GridViewStyle}"
            ItemsSource="{Binding View}"
            SelectionMode="None"
            Local:EventToCommandBehavior.RoutedEvent="ItemClick"
            Local:EventToCommandBehavior.Command="{Binding ItemClickedCommand}"
            ItemTemplate="{StaticResource itemTemplate}">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.GroupStyle>
                <GroupStyle HidesIfEmpty="True">
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="0,0,100,10" Background="#4372AA">
                                <TextBlock Text="{Binding Key, Converter={StaticResource AirViewConverter}}" Foreground="White" Margin="10,2" FontSize="34" FontWeight="Light" />
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>                            
                            <VariableSizedWrapGrid Margin="0,0,100,0" Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>

        <ListView
            x:Name="listView"
            Visibility="Collapsed"
            Style="{StaticResource ListViewStyle}"
            Grid.RowSpan="2"
            Padding="30,0"
            Margin="0,140,0,0"
            SelectionMode="None"
            Local:EventToCommandBehavior.RoutedEvent="ItemClick"
            Local:EventToCommandBehavior.Command="{Binding ItemClickedCommand}"
            ItemsSource="{Binding View}"
            ItemTemplate="{StaticResource itemTemplate}">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="Margin" Value="1" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.GroupStyle>
                <GroupStyle HidesIfEmpty="True">
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="0,0,0,10" Background="#4372AA">
                                <TextBlock Text="{Binding Key, Converter={StaticResource AirViewConverter}}" Foreground="White" Margin="10,2" FontSize="34" FontWeight="Light" />
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid Margin="0,0,0,40" Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <AppBarButton Icon="Back" Height="95" Margin="10,46,10,0" Command="{Binding BackCommand}" Visibility="{Binding IsEnabled, Converter={StaticResource BooleanVisibilityConverter}, RelativeSource={RelativeSource Mode=Self}}"/>
            <TextBlock x:Name="HeaderTextBlock" x:Uid="HeaderUnAired" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
        </Grid>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="Landscape500">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="gridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="listView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Landscape768" />
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Local:NavigationView>
